import keras
import numpy as np
import tensorflow as tf
import pandas as pd
import nibabel as nib
import nilearn as nil
import scipy.ndimage as ndi
import matplotlib.pyplot as plt
from skimage.util import montage
from skimage.transform import rotate,resize
from keras.src.saving import register_keras_serializable
import cv2
import os
from scipy.ndimage import label, binary_dilation
def remove_outer_layer_3d(mask, threshold=0.4):
class1 = (mask == 3)
class3 = (mask == 1)
labeled, num_features = label(class3)
se = np.ones((3, 3, 3), dtype=bool)
for region_id in range(1, num_features + 1):
region = (labeled == region_id)
dilated = binary_dilation(region, structure=se)
border = dilated & (~region)
class1_ratio = np.sum(class1[border]) / border.sum() if border.sum() > 0 else 0
if class1_ratio < threshold:
mask[region] = 2
return mask
def remove_outer_layer(mask,threshold = 0.75):
# mask shape: (H, W)
class1 = (mask == 3)
class3 = (mask == 1)
labeled, num_features = label(class3)
se = np.ones((3, 3), dtype=bool)
for region_id in range(1, num_features + 1):
region = (labeled == region_id)
dilated = binary_dilation(region, structure=se)
border = dilated & (~region)
class1_ratio = np.sum(class1[border]) / border.sum()
if class1_ratio < threshold:
mask[region] = 2
return mask
def ajust_mask(mask):
mask = np.squeeze(mask, axis=0)
mask = np.argmax(mask, axis=-1)
mask = remove_outer_layer_3d(mask)
mask = tf.convert_to_tensor(mask, dtype=tf.int32)
mask = tf.one_hot(mask, depth=4)
mask = tf.expand_dims(mask, axis=0)
return mask
from keras.src.saving import register_keras_serializable
@register_keras_serializable()
def dice_coefficient(y_true, y_pred, smooth=1e-6):
y_true_f = tf.reshape(y_true, [-1])
y_pred_f = tf.reshape(y_pred, [-1])
intersection = tf.reduce_sum(y_true_f * y_pred_f)
union = tf.reduce_sum(y_true_f) + tf.reduce_sum(y_pred_f)
dice = (2. * intersection + smooth) / (union + smooth)
return dice
@register_keras_serializable()
def dice_coef_background(y_true, y_pred, epsilon=1e-6):
intersection = tf.reduce_sum(tf.abs(y_true[:,:,:,:,0] * y_pred[:,:,:,:,0]), axis=[1, 2, 3]) # sum over depth, height, width
return (2. * intersection) / (tf.reduce_sum(tf.square(y_true[:,:,:,:,0]), axis=[1, 2, 3]) + tf.reduce_sum(tf.square(y_pred[:,:,:,:,0]), axis=[1, 2, 3]) + epsilon)
@register_keras_serializable()
def dice_coef_necrotic(y_true, y_pred, epsilon=1e-6):
intersection = tf.reduce_sum(tf.abs(y_true[:,:,:,:,1] * y_pred[:,:,:,:,1]), axis=[1, 2, 3]) # sum over depth, height, width
return (2. * intersection) / (tf.reduce_sum(tf.square(y_true[:,:,:,:,1]), axis=[1, 2, 3]) + tf.reduce_sum(tf.square(y_pred[:,:,:,:,1]), axis=[1, 2, 3]) + epsilon)
@register_keras_serializable()
def dice_coef_edema(y_true, y_pred, epsilon=1e-6):
intersection = tf.reduce_sum(tf.abs(y_true[:,:,:,:,2] * y_pred[:,:,:,:,2]), axis=[1, 2, 3]) # sum over depth, height, width
return (2. * intersection) / (tf.reduce_sum(tf.square(y_true[:,:,:,:,2]), axis=[1, 2, 3]) + tf.reduce_sum(tf.square(y_pred[:,:,:,:,2]), axis=[1, 2, 3]) + epsilon)
@register_keras_serializable()
def dice_coef_enhancing(y_true, y_pred, epsilon=1e-6):
intersection = tf.reduce_sum(tf.abs(y_true[:,:,:,:,3] * y_pred[:,:,:,:,3]), axis=[1, 2, 3]) # sum over depth, height, width
return (2. * intersection) / (tf.reduce_sum(tf.square(y_true[:,:,:,:,3]), axis=[1, 2, 3]) + tf.reduce_sum(tf.square(y_pred[:,:,:,:,3]), axis=[1, 2, 3]) + epsilon)
@register_keras_serializable()
def multi_class_dice_loss(y_true, y_pred, smooth=1e-6):
dice_loss_total = 0.0
#weights = [0.00431145,0.46406451,0.15163813,0.37998591]
weights = [0.1,1.0,0.4,1.0]
num_classes = y_pred.shape[-1]
for class_idx in range(num_classes):
y_true_class = y_true[..., class_idx]
y_pred_class = y_pred[..., class_idx]
dice_coef = dice_coefficient(y_true_class, y_pred_class, smooth)
dice_loss_total += (1 - dice_coef)*weights[class_idx]
return dice_loss_total / num_classes
@register_keras_serializable()
def ajusted_multi_dice(y_true, y_pred, smooth=1e-6):
dice_loss_total = 0.0
#weights = [0.00431145,0.46406451,0.15163813,0.37998591]
weights = [0.04,0.36,0.16,0.44]
dice_func = [dice_coef_background,dice_coef_necrotic,dice_coef_edema,dice_coef_enhancing]
num_classes = y_pred.shape[-1]
for class_idx in range(num_classes):
dice_coef = dice_func[class_idx](y_true, y_pred, smooth)
dice_loss_total += (1 - dice_coef)*weights[class_idx]
return dice_loss_total / num_classes
@register_keras_serializable()
def reverse_containment_penalty(y_pred):
C1 = y_pred[..., 1]
C2 = y_pred[..., 2]
C3 = y_pred[..., 3]
c2_in_c1 = tf.reduce_mean(C2 * C1)
c2_in_c3 = tf.reduce_mean(C2 * C3)
c1_in_c3 = tf.reduce_mean(C1 * C3)
total_violation = c2_in_c1 + c2_in_c3 + c1_in_c3
normalized_penalty = total_violation / 3.0
return normalized_penalty
@register_keras_serializable()
def combined_loss(y_true, y_pred):
dice = ajusted_multi_dice(y_true, y_pred)
cce = keras.losses.CategoricalCrossentropy()
penalty = reverse_containment_penalty(y_pred)
return 0.65*dice + 0.25*cce(y_true, y_pred) + 0.1*penalty
def is_empty(image):
return np.all(image == 0)
def load_nii_file(filepath,mx = 0):
nii_file = nib.load(filepath)
data = np.array(nii_file.get_fdata(), dtype=np.float32)
if is_empty(data):
return data
if mx <= 0:
data = (data-np.min(data)) / (np.max(data)-np.min(data))
brain = data > 0
mean = data[brain].mean()
std = data[brain].std()
data = (data - mean) / std
else:
data = data/mx
data = data[:, :, 14:-13]
return data
def load_nii_dataset(input_filepaths, output_filepaths):
def generator():
for input_file, output_file in zip(input_filepaths, output_filepaths):
flair_nii = load_nii_file(input_file[0])
t1ce_nii = load_nii_file(input_file[1])
t1_nii = load_nii_file(input_file[2])
t2_nii = load_nii_file(input_file[3])
output_nii = load_nii_file(output_file,mx=4)
output_nii = np.floor(output_nii*4)
output_nii = np.where(output_nii == 4, 3, output_nii)
flair_nii = tf.convert_to_tensor(flair_nii, dtype=tf.float32)
t1ce_nii = tf.convert_to_tensor(t1ce_nii, dtype=tf.float32)
t1_nii = tf.convert_to_tensor(t1_nii, dtype=tf.float32)
t2_nii = tf.convert_to_tensor(t2_nii , dtype=tf.float32)
output_nii = tf.convert_to_tensor(output_nii, dtype=tf.int32)
flair_nii = tf.expand_dims(flair_nii, axis=-1)
t1ce_nii = tf.expand_dims(t1ce_nii, axis=-1)
t1_nii = tf.expand_dims(t1_nii, axis=-1)
t2_nii = tf.expand_dims(t2_nii, axis=-1)
input_combined = tf.concat([flair_nii, t1ce_nii, t1_nii, t2_nii], axis=-1)
output_nii = tf.one_hot(output_nii, depth=4)
yield input_combined, output_nii
dataset = tf.data.Dataset.from_generator(
generator=generator,
output_signature=(
tf.TensorSpec(shape=(240,240,128,4), dtype=tf.float32),
tf.TensorSpec(shape=(240,240,128,4), dtype=tf.float32)
)
)
return dataset
def getFile(fileList,fileType):
for i in fileList:
if i.find(fileType) != -1:
return i
print(fileList)
raise FileNotFoundError("File not found")
input_path = '/kaggle/input/brats20-dataset-training-validation/BraTS2020_TrainingData/MICCAI_BraTS2020_TrainingData/BraTS20_Training_010'
fileList = os.listdir(input_path)
input_file = [
getFile(fileList,"_flair."),
getFile(fileList,"_t1ce."),
getFile(fileList,"_t1."),
getFile(fileList,"_t2.")
]
input_file = [os.path.join(input_path, f) for f in input_file]
output_file = os.path.join(input_path,getFile(fileList,"_seg."))
flair_nii = load_nii_file(input_file[0])
t1ce_nii = load_nii_file(input_file[1])
t1_nii = load_nii_file(input_file[2])
t2_nii = load_nii_file(input_file[3])
output_nii = load_nii_file(output_file,mx=4)
output_nii = np.floor(output_nii*4)
output_nii = np.where(output_nii == 4, 3, output_nii)
flair_nii = tf.convert_to_tensor(flair_nii, dtype=tf.float32)
t1ce_nii = tf.convert_to_tensor(t1ce_nii, dtype=tf.float32)
t1_nii = tf.convert_to_tensor(t1_nii, dtype=tf.float32)
t2_nii = tf.convert_to_tensor(t2_nii , dtype=tf.float32)
flair_nii = tf.expand_dims(flair_nii, axis=-1)
t1ce_nii = tf.expand_dims(t1ce_nii, axis=-1)
t1_nii = tf.expand_dims(t1_nii, axis=-1)
t2_nii = tf.expand_dims(t2_nii, axis=-1)
input_combined = tf.concat([flair_nii, t1ce_nii, t1_nii, t2_nii], axis=-1)
model_path = '/kaggle/input/custom_loss_unet/keras/default/1/brats_3d(6).keras'
model2_path = '/kaggle/input/custom_loss_2/keras/default/1/brats_3d(7).keras'
input_combined = tf.expand_dims(input_combined, axis=0)
print(input_combined.shape)
model = keras.models.load_model(model_path)
model.summary()
output = model.predict(input_combined)
output = ajust_mask(output)
print(dice_coef_edema(output,output))
output = np.squeeze(output, axis=0)
output = np.argmax(output, axis=-1)
model = keras.models.load_model(model2_path)
model.summary()
output2 = model.predict(input_combined)
output2 = np.squeeze(output2, axis=0)
output2 = np.argmax(output2, axis=-1)
input_nii = np.squeeze(input_combined, axis=0)
for slice_idx in range(50,151):
plt.figure(figsize=(10, 5))
plt.subplot(1, 4, 1)
plt.imshow(input_nii[slice_idx, :, :, 1], cmap='gray')
plt.title(f'Input Slice {slice_idx}')
plt.axis('off')
segmentation_map = output[slice_idx, :, :]
plt.subplot(1, 4, 2)
plt.imshow(segmentation_map)
plt.title(f'Predicted Slice {slice_idx}')
plt.axis('off')
segmentation_map = output2[slice_idx, :, :]
plt.subplot(1, 4, 3)
plt.imshow(segmentation_map)
plt.title(f'Predicted Slice {slice_idx}')
plt.axis('off')
true_mask = output_nii[slice_idx, :, :]
plt.subplot(1, 4, 4)
plt.imshow(true_mask)
plt.title(f'True Mask {slice_idx}')
plt.axis('off')
plt.show()
2025-05-04 19:22:29.019979: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:477] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered WARNING: All log messages before absl::InitializeLog() is called are written to STDERR E0000 00:00:1746386549.206863 31 cuda_dnn.cc:8310] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered E0000 00:00:1746386549.260032 31 cuda_blas.cc:1418] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered I0000 00:00:1746386563.554628 31 gpu_device.cc:2022] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 15513 MB memory: -> device: 0, name: Tesla P100-PCIE-16GB, pci bus id: 0000:00:04.0, compute capability: 6.0
(1, 240, 240, 128, 4)
Model: "functional"
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Layer (type) ┃ Output Shape ┃ Param # ┃ Connected to ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━┩ │ input_layer (InputLayer) │ (None, 240, 240, 128, │ 0 │ - │ │ │ 4) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d (Conv3D) │ (None, 240, 240, 128, │ 3,488 │ input_layer[0][0] │ │ │ 32) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ leaky_re_lu (LeakyReLU) │ (None, 240, 240, 128, │ 0 │ conv3d[0][0] │ │ │ 32) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_1 (Conv3D) │ (None, 240, 240, 128, │ 27,680 │ leaky_re_lu[0][0] │ │ │ 32) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ leaky_re_lu_1 (LeakyReLU) │ (None, 240, 240, 128, │ 0 │ conv3d_1[0][0] │ │ │ 32) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ max_pooling3d │ (None, 120, 120, 64, │ 0 │ leaky_re_lu_1[0][0] │ │ (MaxPooling3D) │ 32) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_2 (Conv3D) │ (None, 120, 120, 64, │ 55,360 │ max_pooling3d[0][0] │ │ │ 64) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ leaky_re_lu_2 (LeakyReLU) │ (None, 120, 120, 64, │ 0 │ conv3d_2[0][0] │ │ │ 64) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_3 (Conv3D) │ (None, 120, 120, 64, │ 110,656 │ leaky_re_lu_2[0][0] │ │ │ 64) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ leaky_re_lu_3 (LeakyReLU) │ (None, 120, 120, 64, │ 0 │ conv3d_3[0][0] │ │ │ 64) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ max_pooling3d_1 │ (None, 60, 60, 32, 64) │ 0 │ leaky_re_lu_3[0][0] │ │ (MaxPooling3D) │ │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_4 (Conv3D) │ (None, 60, 60, 32, │ 221,312 │ max_pooling3d_1[0][0] │ │ │ 128) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ leaky_re_lu_4 (LeakyReLU) │ (None, 60, 60, 32, │ 0 │ conv3d_4[0][0] │ │ │ 128) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_5 (Conv3D) │ (None, 60, 60, 32, │ 442,496 │ leaky_re_lu_4[0][0] │ │ │ 128) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ leaky_re_lu_5 (LeakyReLU) │ (None, 60, 60, 32, │ 0 │ conv3d_5[0][0] │ │ │ 128) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ max_pooling3d_2 │ (None, 30, 30, 16, │ 0 │ leaky_re_lu_5[0][0] │ │ (MaxPooling3D) │ 128) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_6 (Conv3D) │ (None, 30, 30, 16, │ 884,992 │ max_pooling3d_2[0][0] │ │ │ 256) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ leaky_re_lu_6 (LeakyReLU) │ (None, 30, 30, 16, │ 0 │ conv3d_6[0][0] │ │ │ 256) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_7 (Conv3D) │ (None, 30, 30, 16, │ 1,769,728 │ leaky_re_lu_6[0][0] │ │ │ 256) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ leaky_re_lu_7 (LeakyReLU) │ (None, 30, 30, 16, │ 0 │ conv3d_7[0][0] │ │ │ 256) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ up_sampling3d │ (None, 60, 60, 32, │ 0 │ leaky_re_lu_7[0][0] │ │ (UpSampling3D) │ 256) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_8 (Conv3D) │ (None, 60, 60, 32, │ 442,496 │ leaky_re_lu_5[0][0] │ │ │ 128) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_9 (Conv3D) │ (None, 60, 60, 32, │ 884,864 │ up_sampling3d[0][0] │ │ │ 128) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ add (Add) │ (None, 60, 60, 32, │ 0 │ conv3d_8[0][0], │ │ │ 128) │ │ conv3d_9[0][0] │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ leaky_re_lu_8 (LeakyReLU) │ (None, 60, 60, 32, │ 0 │ add[0][0] │ │ │ 128) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_10 (Conv3D) │ (None, 60, 60, 32, 1) │ 3,457 │ leaky_re_lu_8[0][0] │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ multiply (Multiply) │ (None, 60, 60, 32, │ 0 │ leaky_re_lu_5[0][0], │ │ │ 128) │ │ conv3d_10[0][0] │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_11 (Conv3D) │ (None, 60, 60, 32, │ 442,496 │ multiply[0][0] │ │ │ 128) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ leaky_re_lu_9 (LeakyReLU) │ (None, 60, 60, 32, │ 0 │ conv3d_11[0][0] │ │ │ 128) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_12 (Conv3D) │ (None, 60, 60, 32, │ 442,496 │ leaky_re_lu_9[0][0] │ │ │ 128) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ leaky_re_lu_10 │ (None, 60, 60, 32, │ 0 │ conv3d_12[0][0] │ │ (LeakyReLU) │ 128) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ up_sampling3d_1 │ (None, 120, 120, 64, │ 0 │ leaky_re_lu_10[0][0] │ │ (UpSampling3D) │ 128) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_13 (Conv3D) │ (None, 120, 120, 64, │ 110,656 │ leaky_re_lu_3[0][0] │ │ │ 64) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_14 (Conv3D) │ (None, 120, 120, 64, │ 221,248 │ up_sampling3d_1[0][0] │ │ │ 64) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ add_1 (Add) │ (None, 120, 120, 64, │ 0 │ conv3d_13[0][0], │ │ │ 64) │ │ conv3d_14[0][0] │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ leaky_re_lu_11 │ (None, 120, 120, 64, │ 0 │ add_1[0][0] │ │ (LeakyReLU) │ 64) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_15 (Conv3D) │ (None, 120, 120, 64, │ 1,729 │ leaky_re_lu_11[0][0] │ │ │ 1) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ multiply_1 (Multiply) │ (None, 120, 120, 64, │ 0 │ leaky_re_lu_3[0][0], │ │ │ 64) │ │ conv3d_15[0][0] │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_16 (Conv3D) │ (None, 120, 120, 64, │ 110,656 │ multiply_1[0][0] │ │ │ 64) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ leaky_re_lu_12 │ (None, 120, 120, 64, │ 0 │ conv3d_16[0][0] │ │ (LeakyReLU) │ 64) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_17 (Conv3D) │ (None, 120, 120, 64, │ 110,656 │ leaky_re_lu_12[0][0] │ │ │ 64) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ leaky_re_lu_13 │ (None, 120, 120, 64, │ 0 │ conv3d_17[0][0] │ │ (LeakyReLU) │ 64) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ up_sampling3d_2 │ (None, 240, 240, 128, │ 0 │ leaky_re_lu_13[0][0] │ │ (UpSampling3D) │ 64) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_18 (Conv3D) │ (None, 240, 240, 128, │ 27,680 │ leaky_re_lu_1[0][0] │ │ │ 32) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_19 (Conv3D) │ (None, 240, 240, 128, │ 55,328 │ up_sampling3d_2[0][0] │ │ │ 32) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ add_2 (Add) │ (None, 240, 240, 128, │ 0 │ conv3d_18[0][0], │ │ │ 32) │ │ conv3d_19[0][0] │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ leaky_re_lu_14 │ (None, 240, 240, 128, │ 0 │ add_2[0][0] │ │ (LeakyReLU) │ 32) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_20 (Conv3D) │ (None, 240, 240, 128, │ 865 │ leaky_re_lu_14[0][0] │ │ │ 1) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ multiply_2 (Multiply) │ (None, 240, 240, 128, │ 0 │ leaky_re_lu_1[0][0], │ │ │ 32) │ │ conv3d_20[0][0] │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_21 (Conv3D) │ (None, 240, 240, 128, │ 27,680 │ multiply_2[0][0] │ │ │ 32) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ leaky_re_lu_15 │ (None, 240, 240, 128, │ 0 │ conv3d_21[0][0] │ │ (LeakyReLU) │ 32) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_22 (Conv3D) │ (None, 240, 240, 128, │ 27,680 │ leaky_re_lu_15[0][0] │ │ │ 32) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ leaky_re_lu_16 │ (None, 240, 240, 128, │ 0 │ conv3d_22[0][0] │ │ (LeakyReLU) │ 32) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_23 (Conv3D) │ (None, 240, 240, 128, │ 132 │ leaky_re_lu_16[0][0] │ │ │ 4) │ │ │ └───────────────────────────┴────────────────────────┴────────────────┴────────────────────────┘
Total params: 19,277,495 (73.54 MB)
Trainable params: 6,425,831 (24.51 MB)
Non-trainable params: 0 (0.00 B)
Optimizer params: 12,851,664 (49.03 MB)
WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
I0000 00:00:1746386567.330365 90 service.cc:148] XLA service 0x7b12d040fde0 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
I0000 00:00:1746386567.331244 90 service.cc:156] StreamExecutor device (0): Tesla P100-PCIE-16GB, Compute Capability 6.0
I0000 00:00:1746386567.467368 90 cuda_dnn.cc:529] Loaded cuDNN version 90300
E0000 00:00:1746386568.662194 90 gpu_timer.cc:82] Delay kernel timed out: measured time has sub-optimal accuracy. There may be a missing warmup execution, please investigate in Nsight Systems.
2025-05-04 19:22:48.921883: E external/local_xla/xla/service/slow_operation_alarm.cc:65] Trying algorithm eng13{} for conv (f32[1,32,240,240,128]{4,3,2,1,0}, u8[0]{0}) custom-call(f32[1,4,240,240,128]{4,3,2,1,0}, f32[32,4,3,3,3]{4,3,2,1,0}, f32[32]{0}), window={size=3x3x3 pad=1_1x1_1x1_1}, dim_labels=bf012_oi012->bf012, custom_call_target="__cudnn$convBiasActivationForward", backend_config={"cudnn_conv_backend_config":{"activation_mode":"kNone","conv_result_scale":1,"leakyrelu_alpha":0,"side_input_scale":0},"force_earliest_schedule":false,"operation_queue_id":"0","wait_on_operation_queues":[]} is taking a while...
E0000 00:00:1746386569.097065 90 gpu_timer.cc:82] Delay kernel timed out: measured time has sub-optimal accuracy. There may be a missing warmup execution, please investigate in Nsight Systems.
2025-05-04 19:22:49.140371: E external/local_xla/xla/service/slow_operation_alarm.cc:133] The operation took 1.218592426s
Trying algorithm eng13{} for conv (f32[1,32,240,240,128]{4,3,2,1,0}, u8[0]{0}) custom-call(f32[1,4,240,240,128]{4,3,2,1,0}, f32[32,4,3,3,3]{4,3,2,1,0}, f32[32]{0}), window={size=3x3x3 pad=1_1x1_1x1_1}, dim_labels=bf012_oi012->bf012, custom_call_target="__cudnn$convBiasActivationForward", backend_config={"cudnn_conv_backend_config":{"activation_mode":"kNone","conv_result_scale":1,"leakyrelu_alpha":0,"side_input_scale":0},"force_earliest_schedule":false,"operation_queue_id":"0","wait_on_operation_queues":[]} is taking a while...
E0000 00:00:1746386570.400601 90 gpu_timer.cc:82] Delay kernel timed out: measured time has sub-optimal accuracy. There may be a missing warmup execution, please investigate in Nsight Systems.
2025-05-04 19:22:50.646188: E external/local_xla/xla/service/slow_operation_alarm.cc:65] Trying algorithm eng13{} for conv (f32[1,32,240,240,128]{4,3,2,1,0}, u8[0]{0}) custom-call(f32[1,32,240,240,128]{4,3,2,1,0}, f32[32,32,3,3,3]{4,3,2,1,0}, f32[32]{0}), window={size=3x3x3 pad=1_1x1_1x1_1}, dim_labels=bf012_oi012->bf012, custom_call_target="__cudnn$convBiasActivationForward", backend_config={"cudnn_conv_backend_config":{"activation_mode":"kNone","conv_result_scale":1,"leakyrelu_alpha":0,"side_input_scale":0},"force_earliest_schedule":false,"operation_queue_id":"0","wait_on_operation_queues":[]} is taking a while...
E0000 00:00:1746386570.873151 90 gpu_timer.cc:82] Delay kernel timed out: measured time has sub-optimal accuracy. There may be a missing warmup execution, please investigate in Nsight Systems.
2025-05-04 19:22:50.919744: E external/local_xla/xla/service/slow_operation_alarm.cc:133] The operation took 1.273729538s
Trying algorithm eng13{} for conv (f32[1,32,240,240,128]{4,3,2,1,0}, u8[0]{0}) custom-call(f32[1,32,240,240,128]{4,3,2,1,0}, f32[32,32,3,3,3]{4,3,2,1,0}, f32[32]{0}), window={size=3x3x3 pad=1_1x1_1x1_1}, dim_labels=bf012_oi012->bf012, custom_call_target="__cudnn$convBiasActivationForward", backend_config={"cudnn_conv_backend_config":{"activation_mode":"kNone","conv_result_scale":1,"leakyrelu_alpha":0,"side_input_scale":0},"force_earliest_schedule":false,"operation_queue_id":"0","wait_on_operation_queues":[]} is taking a while...
E0000 00:00:1746386579.265057 90 gpu_timer.cc:82] Delay kernel timed out: measured time has sub-optimal accuracy. There may be a missing warmup execution, please investigate in Nsight Systems.
2025-05-04 19:22:59.360886: E external/local_xla/xla/service/slow_operation_alarm.cc:65] Trying algorithm eng13{} for conv (f32[1,32,240,240,128]{4,3,2,1,0}, u8[0]{0}) custom-call(f32[1,64,240,240,128]{4,3,2,1,0}, f32[32,64,3,3,3]{4,3,2,1,0}, f32[32]{0}), window={size=3x3x3 pad=1_1x1_1x1_1}, dim_labels=bf012_oi012->bf012, custom_call_target="__cudnn$convBiasActivationForward", backend_config={"cudnn_conv_backend_config":{"activation_mode":"kNone","conv_result_scale":1,"leakyrelu_alpha":0,"side_input_scale":0},"force_earliest_schedule":false,"operation_queue_id":"0","wait_on_operation_queues":[]} is taking a while...
E0000 00:00:1746386579.814900 90 gpu_timer.cc:82] Delay kernel timed out: measured time has sub-optimal accuracy. There may be a missing warmup execution, please investigate in Nsight Systems.
2025-05-04 19:22:59.870033: E external/local_xla/xla/service/slow_operation_alarm.cc:133] The operation took 1.509239034s
Trying algorithm eng13{} for conv (f32[1,32,240,240,128]{4,3,2,1,0}, u8[0]{0}) custom-call(f32[1,64,240,240,128]{4,3,2,1,0}, f32[32,64,3,3,3]{4,3,2,1,0}, f32[32]{0}), window={size=3x3x3 pad=1_1x1_1x1_1}, dim_labels=bf012_oi012->bf012, custom_call_target="__cudnn$convBiasActivationForward", backend_config={"cudnn_conv_backend_config":{"activation_mode":"kNone","conv_result_scale":1,"leakyrelu_alpha":0,"side_input_scale":0},"force_earliest_schedule":false,"operation_queue_id":"0","wait_on_operation_queues":[]} is taking a while...
E0000 00:00:1746386581.173141 90 gpu_timer.cc:82] Delay kernel timed out: measured time has sub-optimal accuracy. There may be a missing warmup execution, please investigate in Nsight Systems.
2025-05-04 19:23:01.386257: E external/local_xla/xla/service/slow_operation_alarm.cc:65] Trying algorithm eng13{} for conv (f32[1,32,240,240,128]{4,3,2,1,0}, u8[0]{0}) custom-call(f32[1,32,240,240,128]{4,3,2,1,0}, f32[32,32,3,3,3]{4,3,2,1,0}, f32[32]{0}, f32[1,32,240,240,128]{4,3,2,1,0}), window={size=3x3x3 pad=1_1x1_1x1_1}, dim_labels=bf012_oi012->bf012, custom_call_target="__cudnn$convBiasActivationForward", backend_config={"cudnn_conv_backend_config":{"activation_mode":"kNone","conv_result_scale":1,"leakyrelu_alpha":0,"side_input_scale":1},"force_earliest_schedule":false,"operation_queue_id":"0","wait_on_operation_queues":[]} is taking a while...
E0000 00:00:1746386581.661530 90 gpu_timer.cc:82] Delay kernel timed out: measured time has sub-optimal accuracy. There may be a missing warmup execution, please investigate in Nsight Systems.
2025-05-04 19:23:01.709869: E external/local_xla/xla/service/slow_operation_alarm.cc:133] The operation took 1.323692549s
Trying algorithm eng13{} for conv (f32[1,32,240,240,128]{4,3,2,1,0}, u8[0]{0}) custom-call(f32[1,32,240,240,128]{4,3,2,1,0}, f32[32,32,3,3,3]{4,3,2,1,0}, f32[32]{0}, f32[1,32,240,240,128]{4,3,2,1,0}), window={size=3x3x3 pad=1_1x1_1x1_1}, dim_labels=bf012_oi012->bf012, custom_call_target="__cudnn$convBiasActivationForward", backend_config={"cudnn_conv_backend_config":{"activation_mode":"kNone","conv_result_scale":1,"leakyrelu_alpha":0,"side_input_scale":1},"force_earliest_schedule":false,"operation_queue_id":"0","wait_on_operation_queues":[]} is taking a while...
E0000 00:00:1746386582.110825 90 gpu_timer.cc:82] Delay kernel timed out: measured time has sub-optimal accuracy. There may be a missing warmup execution, please investigate in Nsight Systems.
E0000 00:00:1746386582.389356 90 gpu_timer.cc:82] Delay kernel timed out: measured time has sub-optimal accuracy. There may be a missing warmup execution, please investigate in Nsight Systems.
E0000 00:00:1746386583.481013 90 gpu_timer.cc:82] Delay kernel timed out: measured time has sub-optimal accuracy. There may be a missing warmup execution, please investigate in Nsight Systems.
E0000 00:00:1746386583.708792 90 gpu_timer.cc:82] Delay kernel timed out: measured time has sub-optimal accuracy. There may be a missing warmup execution, please investigate in Nsight Systems.
I0000 00:00:1746386584.338117 90 device_compiler.h:188] Compiled cluster using XLA! This line is logged at most once for the lifetime of the process.
1/1 ━━━━━━━━━━━━━━━━━━━━ 19s 19s/step tf.Tensor([1.], shape=(1,), dtype=float32)
Model: "functional"
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Layer (type) ┃ Output Shape ┃ Param # ┃ Connected to ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━┩ │ input_layer (InputLayer) │ (None, 240, 240, 128, │ 0 │ - │ │ │ 4) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d (Conv3D) │ (None, 240, 240, 128, │ 3,488 │ input_layer[0][0] │ │ │ 32) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ leaky_re_lu (LeakyReLU) │ (None, 240, 240, 128, │ 0 │ conv3d[0][0] │ │ │ 32) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_1 (Conv3D) │ (None, 240, 240, 128, │ 27,680 │ leaky_re_lu[0][0] │ │ │ 32) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ leaky_re_lu_1 (LeakyReLU) │ (None, 240, 240, 128, │ 0 │ conv3d_1[0][0] │ │ │ 32) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ max_pooling3d │ (None, 120, 120, 64, │ 0 │ leaky_re_lu_1[0][0] │ │ (MaxPooling3D) │ 32) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_2 (Conv3D) │ (None, 120, 120, 64, │ 55,360 │ max_pooling3d[0][0] │ │ │ 64) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ leaky_re_lu_2 (LeakyReLU) │ (None, 120, 120, 64, │ 0 │ conv3d_2[0][0] │ │ │ 64) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_3 (Conv3D) │ (None, 120, 120, 64, │ 110,656 │ leaky_re_lu_2[0][0] │ │ │ 64) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ leaky_re_lu_3 (LeakyReLU) │ (None, 120, 120, 64, │ 0 │ conv3d_3[0][0] │ │ │ 64) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ max_pooling3d_1 │ (None, 60, 60, 32, 64) │ 0 │ leaky_re_lu_3[0][0] │ │ (MaxPooling3D) │ │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_4 (Conv3D) │ (None, 60, 60, 32, │ 221,312 │ max_pooling3d_1[0][0] │ │ │ 128) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ leaky_re_lu_4 (LeakyReLU) │ (None, 60, 60, 32, │ 0 │ conv3d_4[0][0] │ │ │ 128) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_5 (Conv3D) │ (None, 60, 60, 32, │ 442,496 │ leaky_re_lu_4[0][0] │ │ │ 128) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ leaky_re_lu_5 (LeakyReLU) │ (None, 60, 60, 32, │ 0 │ conv3d_5[0][0] │ │ │ 128) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ max_pooling3d_2 │ (None, 30, 30, 16, │ 0 │ leaky_re_lu_5[0][0] │ │ (MaxPooling3D) │ 128) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_6 (Conv3D) │ (None, 30, 30, 16, │ 884,992 │ max_pooling3d_2[0][0] │ │ │ 256) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ leaky_re_lu_6 (LeakyReLU) │ (None, 30, 30, 16, │ 0 │ conv3d_6[0][0] │ │ │ 256) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_7 (Conv3D) │ (None, 30, 30, 16, │ 1,769,728 │ leaky_re_lu_6[0][0] │ │ │ 256) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ leaky_re_lu_7 (LeakyReLU) │ (None, 30, 30, 16, │ 0 │ conv3d_7[0][0] │ │ │ 256) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ up_sampling3d │ (None, 60, 60, 32, │ 0 │ leaky_re_lu_7[0][0] │ │ (UpSampling3D) │ 256) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_8 (Conv3D) │ (None, 60, 60, 32, │ 442,496 │ leaky_re_lu_5[0][0] │ │ │ 128) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_9 (Conv3D) │ (None, 60, 60, 32, │ 884,864 │ up_sampling3d[0][0] │ │ │ 128) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ add (Add) │ (None, 60, 60, 32, │ 0 │ conv3d_8[0][0], │ │ │ 128) │ │ conv3d_9[0][0] │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ leaky_re_lu_8 (LeakyReLU) │ (None, 60, 60, 32, │ 0 │ add[0][0] │ │ │ 128) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_10 (Conv3D) │ (None, 60, 60, 32, 1) │ 3,457 │ leaky_re_lu_8[0][0] │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ multiply (Multiply) │ (None, 60, 60, 32, │ 0 │ leaky_re_lu_5[0][0], │ │ │ 128) │ │ conv3d_10[0][0] │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_11 (Conv3D) │ (None, 60, 60, 32, │ 442,496 │ multiply[0][0] │ │ │ 128) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ leaky_re_lu_9 (LeakyReLU) │ (None, 60, 60, 32, │ 0 │ conv3d_11[0][0] │ │ │ 128) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_12 (Conv3D) │ (None, 60, 60, 32, │ 442,496 │ leaky_re_lu_9[0][0] │ │ │ 128) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ leaky_re_lu_10 │ (None, 60, 60, 32, │ 0 │ conv3d_12[0][0] │ │ (LeakyReLU) │ 128) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ up_sampling3d_1 │ (None, 120, 120, 64, │ 0 │ leaky_re_lu_10[0][0] │ │ (UpSampling3D) │ 128) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_13 (Conv3D) │ (None, 120, 120, 64, │ 110,656 │ leaky_re_lu_3[0][0] │ │ │ 64) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_14 (Conv3D) │ (None, 120, 120, 64, │ 221,248 │ up_sampling3d_1[0][0] │ │ │ 64) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ add_1 (Add) │ (None, 120, 120, 64, │ 0 │ conv3d_13[0][0], │ │ │ 64) │ │ conv3d_14[0][0] │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ leaky_re_lu_11 │ (None, 120, 120, 64, │ 0 │ add_1[0][0] │ │ (LeakyReLU) │ 64) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_15 (Conv3D) │ (None, 120, 120, 64, │ 1,729 │ leaky_re_lu_11[0][0] │ │ │ 1) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ multiply_1 (Multiply) │ (None, 120, 120, 64, │ 0 │ leaky_re_lu_3[0][0], │ │ │ 64) │ │ conv3d_15[0][0] │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_16 (Conv3D) │ (None, 120, 120, 64, │ 110,656 │ multiply_1[0][0] │ │ │ 64) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ leaky_re_lu_12 │ (None, 120, 120, 64, │ 0 │ conv3d_16[0][0] │ │ (LeakyReLU) │ 64) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_17 (Conv3D) │ (None, 120, 120, 64, │ 110,656 │ leaky_re_lu_12[0][0] │ │ │ 64) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ leaky_re_lu_13 │ (None, 120, 120, 64, │ 0 │ conv3d_17[0][0] │ │ (LeakyReLU) │ 64) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ up_sampling3d_2 │ (None, 240, 240, 128, │ 0 │ leaky_re_lu_13[0][0] │ │ (UpSampling3D) │ 64) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_18 (Conv3D) │ (None, 240, 240, 128, │ 27,680 │ leaky_re_lu_1[0][0] │ │ │ 32) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_19 (Conv3D) │ (None, 240, 240, 128, │ 55,328 │ up_sampling3d_2[0][0] │ │ │ 32) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ add_2 (Add) │ (None, 240, 240, 128, │ 0 │ conv3d_18[0][0], │ │ │ 32) │ │ conv3d_19[0][0] │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ leaky_re_lu_14 │ (None, 240, 240, 128, │ 0 │ add_2[0][0] │ │ (LeakyReLU) │ 32) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_20 (Conv3D) │ (None, 240, 240, 128, │ 865 │ leaky_re_lu_14[0][0] │ │ │ 1) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ multiply_2 (Multiply) │ (None, 240, 240, 128, │ 0 │ leaky_re_lu_1[0][0], │ │ │ 32) │ │ conv3d_20[0][0] │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_21 (Conv3D) │ (None, 240, 240, 128, │ 27,680 │ multiply_2[0][0] │ │ │ 32) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ leaky_re_lu_15 │ (None, 240, 240, 128, │ 0 │ conv3d_21[0][0] │ │ (LeakyReLU) │ 32) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_22 (Conv3D) │ (None, 240, 240, 128, │ 27,680 │ leaky_re_lu_15[0][0] │ │ │ 32) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ leaky_re_lu_16 │ (None, 240, 240, 128, │ 0 │ conv3d_22[0][0] │ │ (LeakyReLU) │ 32) │ │ │ ├───────────────────────────┼────────────────────────┼────────────────┼────────────────────────┤ │ conv3d_23 (Conv3D) │ (None, 240, 240, 128, │ 132 │ leaky_re_lu_16[0][0] │ │ │ 4) │ │ │ └───────────────────────────┴────────────────────────┴────────────────┴────────────────────────┘
Total params: 19,277,495 (73.54 MB)
Trainable params: 6,425,831 (24.51 MB)
Non-trainable params: 0 (0.00 B)
Optimizer params: 12,851,664 (49.03 MB)
1/1 ━━━━━━━━━━━━━━━━━━━━ 2s 2s/step
train_path = '/kaggle/input/brats20-dataset-training-validation/BraTS2020_TrainingData/MICCAI_BraTS2020_TrainingData'
input_files = []
output_files = []
def getFile(fileList,fileType):
for i in fileList:
if i.find(fileType) != -1:
return i
print(fileList)
raise FileNotFoundError("File not found")
for folder in os.listdir(train_path):
try:
folder_path = os.path.join(train_path,folder)
fileList = os.listdir(folder_path)
input_file = [
getFile(fileList,"_flair."),
getFile(fileList,"_t1ce."),
getFile(fileList,"_t1."),
getFile(fileList,"_t2.")
]
output_file = getFile(fileList,"_seg.")
input_files.append([os.path.join(folder_path, f) for f in input_file])
output_files.append(os.path.join(folder_path,output_file))
except:
print("Bad file format")
print(fileList)
Bad file format ['BraTS20_Training_032_t2.nii', 'BraTS20_Training_032_t1ce.nii', 'BraTS20_Training_032_flair.nii', 'BraTS20_Training_032_t1.nii', 'BraTS20_Training_032_seg.nii'] Bad file format ['BraTS20_Training_135_t2.nii', 'BraTS20_Training_135_seg.nii', 'BraTS20_Training_135_t1.nii', 'BraTS20_Training_135_flair.nii', 'BraTS20_Training_135_t1ce.nii'] ['BraTS20_Training_355_flair.nii', 'W39_1998.09.19_Segm.nii', 'BraTS20_Training_355_t2.nii', 'BraTS20_Training_355_t1.nii', 'BraTS20_Training_355_t1ce.nii'] Bad file format ['BraTS20_Training_355_flair.nii', 'W39_1998.09.19_Segm.nii', 'BraTS20_Training_355_t2.nii', 'BraTS20_Training_355_t1.nii', 'BraTS20_Training_355_t1ce.nii']
from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test = train_test_split(input_files,output_files,train_size=0.82,random_state=42)
test_dataset = load_nii_dataset(X_test,y_test)
model = keras.models.load_model(model_path)
dice_coefficient
dice_coef_background
dice_coef_necrotic
dice_coef_edema
dice_coef_enhancing
dice = []
dice_background = []
dice_1 = []
dice_2 = []
dice_3 = []
model = keras.models.load_model(model_path)
def get_score(tensor_list):
np_array = np.array([t.numpy() for t in tensor_list])
mean_value = np.mean(np_array)
return float(mean_value)*100
# Scores before ajustment:
# Accuracy: 99.38254356384277%
# Background Accuracy: 99.87772703170776%
# Necrotic Accuracy: 60.02454161643982%
# Edema Accuracy: 72.69161343574524%
# Enhancing: 75.95497369766235%
for X_true,y_true in test_dataset:
X_true = tf.expand_dims(X_true,axis=0)
y_true = tf.expand_dims(y_true,axis=0)
y_pred = ajust_mask(model.predict(X_true))
dice.append(dice_coefficient(y_true,y_pred))
dice_background.append(dice_coef_background(y_true,y_pred))
dice_1.append(dice_coef_necrotic(y_true,y_pred))
dice_2.append(dice_coef_edema(y_true,y_pred))
dice_3.append(dice_coef_enhancing(y_true,y_pred))
print(f"Accuracy: {get_score(dice)}%")
print(f"Background Accuracy: {get_score(dice_background)}%")
print(f"Necrotic Accuracy: {get_score(dice_1)}%")
print(f"Edema Accuracy: {get_score(dice_2)}%")
print(f"Enhancing: {get_score(dice_3)}%")
1/1 ━━━━━━━━━━━━━━━━━━━━ 3s 3s/step 1/1 ━━━━━━━━━━━━━━━━━━━━ 1s 658ms/step 1/1 ━━━━━━━━━━━━━━━━━━━━ 1s 645ms/step 1/1 ━━━━━━━━━━━━━━━━━━━━ 1s 646ms/step 1/1 ━━━━━━━━━━━━━━━━━━━━ 1s 680ms/step 1/1 ━━━━━━━━━━━━━━━━━━━━ 1s 648ms/step 1/1 ━━━━━━━━━━━━━━━━━━━━ 1s 653ms/step 1/1 ━━━━━━━━━━━━━━━━━━━━ 1s 661ms/step 1/1 ━━━━━━━━━━━━━━━━━━━━ 1s 647ms/step 1/1 ━━━━━━━━━━━━━━━━━━━━ 1s 666ms/step 1/1 ━━━━━━━━━━━━━━━━━━━━ 1s 646ms/step 1/1 ━━━━━━━━━━━━━━━━━━━━ 1s 665ms/step